package com.share.three.cluster;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class Sender {
	
	public static void main(String[] args) throws Exception{
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
				ActiveMQConnectionFactory.DEFAULT_USER, 
				ActiveMQConnectionFactory.DEFAULT_PASSWORD, 
				"failover:(tcp://ip:51511,tcp://ip:51512,tcp://ip:51513)?Randomize=false");
		
		Connection connection = connectionFactory.createConnection();
		connection.start();
		
		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Destination destination = session.createQueue("test1");
		MessageProducer messageProducer = session.createProducer(null);
		
		for (int i = 0; i < 5000; i++) {
			TextMessage textMessage = session.createTextMessage("我是message " + i);
			messageProducer.send(destination, textMessage);
			//messageProducer.send(destination, textMessage, DeliveryMode.PERSISTENT, 0 , 20L);
			System.out.println("发送消息：" + textMessage.getText());
			Thread.sleep(1000);
		}

	}
	
	
}
